<%@ page import="com.restfb.*" %>
<%@ page import="com.restfb.types.*" %>
<%@ page import="com.google.unizone.client.SessionManager" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.google.unizone.server.DB_Logic" %>
<%@ page import="com.google.unizone.server.IShiur" %>
<%@ page import="com.google.unizone.server.*" %>



<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <link type="text/css" rel="stylesheet" href="style.css">
  
    <script language="JavaScript" type="text/javascript">
<!-- Copyright 2005, Sandeep Gangadharan -->
<!-- collapse code -->
<!--
if (document.getElementById) {
document.writeln('<style type="text/css"><!--')
document.writeln('.texter {display:none} @media print {.texter {display:block;}}')
document.writeln('//--></style>') }

function openClose(theID) {
if (document.getElementById(theID).style.display == "block") { document.getElementById(theID).style.display = "none" }
else { document.getElementById(theID).style.display = "block" } }
// -->
</script>
  </head>
  <body>
  		<div id = "allWhiteBox">
  	<%=Utils.appToString("register")%>
  	<%
  	String FBid = request.getParameter("FBid");
  	String schedule = request.getParameter("schedule");
	String youtubeLink = "http://www.youtube.com/watch?v=CCm1z3AW-M4";
  	if (schedule == null){%>
  		
  		<p>
 			<div onClick="openClose('a3')" style="cursor:hand; cursor:pointer"><h2 id = "headline">Schedule Settings</h2></div>
			<div id="a3" class="texter"> 				
 				<p id = "line">Welcome to UniZone app! where you can find your campus friends. <br> 
 				On this page you should fill in your class schedule, follow these instructions: <br>
 				1. Login to <a href="http:\\ims.tau.ac.il" target="_blank">ims.tau.ac.il.</a><br>
 				2. Copy your class schedule, paste it to the box below, and press submit. <br>
 				3. It is also recommended to watch this <a href= <%=youtubeLink%> target="_blank">tutorial</a>. <br>
 				4. Start enjoying UniZone!</p>
			</div>
 		</p>
  		<form method="post" action="register.jsp">
		<form name="Registration">

	
	
	<div ><h3 id = "sub_header">University</h3>
	<select name="University">
		<option>TAU</option>
	</select></div>
	<div ><h3 id = "sub_header">Year</h3>
	<select name ="Year">
		<option>2011</option>
	</select></div>
	<input type="hidden" name="FBid" value=<%=FBid%>>
	<div><h3 id = "sub_header">Class Schedule</h3></div>
	<div><textarea name="schedule" cols="90" rows="10">
		
	</textarea></div><br>
	<input type="submit" value="Submit" onSubmit="location.href='register.jsp?FBid=<%=FBid%>'" />
	
</form>
  		
  	<%}
  	else {
  		String year = request.getParameter("Year");
		String university = request.getParameter("University");
				%><%=year%>
				<%=university%><%
  		List<String> courseUIDs = Utils.parseCourseIDs(schedule);
  		Student student = DB_Logic.getStudent(FBid);
  		
  		
  		if(student == null)
  		{
  			student = new Student(FBid);
  			Utils.CreateSchedule(courseUIDs ,student);
  			DB_Logic.createStudent(student);
  		}
  		else {
  			Utils.CreateSchedule(courseUIDs ,student);
  			DB_Logic.updateStudent(student);
  		}
  		
 		String CANVAS_APP_URL = System.getProperty("CANVAS_APP_URL");
 		String url = CANVAS_APP_URL + "index.jsp";
		%> 

 				<script type="text/javascript">
           			top.location = "<%=url%>";
  				</script> 		
  		
 	<%}%>
 	</div>
  </body>
	
</html>